package pso.velocity;

import static java.lang.Math.abs;
import static java.lang.Math.sqrt;

public class ConstrictionFactorVelocityUpdateStrategy extends
		AbstractVelocityUpdateStrategy {

	@Override
	public double calculateNewVelocity(double currentVelocity,
			double cognitivePart, double socialPart) {
		double cf = calculateConstrictionFactor(getCognitiveFactor(),
				getSocialFactor());
		return cf * (currentVelocity + cognitivePart + socialPart);
	}

	public static double calculateConstrictionFactor(double c1, double c2) {
		double phi = c1 + c2;
		double div = abs(2 - phi - sqrt(phi * phi - 4 * phi));
		return 2 / div;
	}
}
